<script lang="ts" setup>
import { onMounted, PropType } from 'vue'
import { Command } from '@/commands/command.ts'
import { copy_to_clipboard } from '@/functions/clipboard.ts'
import { dbus } from '@/dbus/dbus.ts'

const props = defineProps({
    command: { required: true, type: Object as PropType<Command> },
})

onMounted(async () => {
    props.command!.execute().finally(async () => {
        dbus.emit('scroll-to-bottom')
    })
})
</script>

<template>
    <n-space :size="3" :wrap-item="false" vertical>
        <n-space :wrap-item="false" align="center" class="session-message">
            <div>{{ props.command!.output }}</div>
        </n-space>
        <n-space :wrap="false" :wrap-item="false" align="center">
            <n-text :disabled="!props.command!.success" class="desc-button pointer" type="info" @click="copy_to_clipboard(props.command!.output)">复制</n-text>
        </n-space>
    </n-space>
</template>

<style lang="scss" scoped></style>
